package cn.siat.gene.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.siat.common.security.utils.SecurityUtils;
import cn.siat.gene.domain.Logs;
import cn.siat.gene.mapper.LogsMapper;
import cn.siat.gene.service.LogsService;
import cn.siat.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 日志Service业务层处理
 * 
 * @author siat
 * @date 2022-10-08
 */
@Service
public class LogsServiceImpl extends ServiceImpl<LogsMapper,Logs> implements LogsService {
    @Autowired
    private LogsMapper logsMapper;

    /**
     * 查询日志列表
     * 
     * @param relationId
     * @return 日志
     */
    @Override
    public List<Logs> selectLogsList(String relationId) {
        return logsMapper.selectLogsList(relationId);
    }

    @Async
    @Override
    public void saveLog(String relationId, String operationType, String operationModule, String objectSource, String operationLog) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        String userId = loginUser.getUserid();
        String nickName = loginUser.getSysUser().getNickName();
        Logs logs = new Logs().setRelationId(relationId).setStaffId(SecurityUtils.getUserId()).
                setOperationType(operationType).setOperationModule(operationModule).
                setObjectSource(objectSource).setOperationLog(operationLog).
                setCreateStaffName(nickName).setCreateStaffNo(userId).
                setUpdateStaffNo(userId);
        logsMapper.insert(logs);
    }
}
